package r21310.chap06.d1117;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo02 {
    public static void main(String[] args) {
        List<person> list=new ArrayList<>();
        list.add(new person("刘备","蜀国"));
        list.add(new person("关羽","蜀国"));
        list.add(new person("张飞","蜀国"));
        list.add(new person("赵云","蜀国"));
        list.add(new person("曹操","魏国"));
        list.add(new person("孙权","吴国"));
    //集合的便利
        //增强for
        for (person per:list) {
            System.out.print(per);
        }
        //Lambda的foreach
        list.forEach(aa->{System.out.print(aa);});
        //迭带器
        //创建迭代器对象
        Iterator <person>it=list.listIterator();
        while (it.hasNext()){
            person p=it.next();
            System.out.println(p.getName());
        }
        //传统的for循环
        for (int i = 0; i < list.size(); i++) {
            person p=list.get(i);
            System.out.println(p.getCountry());
        }
        //有条件的删除，修改，查询

    }
}
class person{
    private String name;
    private String country;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public person(String name, String country) {
        this.name = name;
        this.country = country;
    }

    @Override
    public String toString() {
        return this.name+this.country;
    }
}
